package com.runjian.rundo.iot.agent.common.network.tcp.parser;

/**
 * tcp字节流拆包类型
 *
 * @author LiGang
 */
public enum PayloadParserType {

    /**
     * 直接返回，不处理拆包
     */
    DIRECT("direct", "不处理"),

    /**
     * 固定长度
     */
    FIXED_LENGTH("fixed", "固定长度"),

    /**
     * 分隔符
     */
    DELIMITED("delimiter","分隔符"),

    /**
     * 暂不支持（由具体的Agent自行注入ByteToMessageDecoder到ioc中）
     * see {@link io.netty.handler.codec.ByteToMessageDecoder}
     */
    CUSTOM("custom", "自定义"),

    /**
     * 基于长度字段
     */
    LENGTH_FIELD("lengthField", "长度字段"),
    ;

    private final String key;

    private final String text;

    PayloadParserType(String key, String text) {
        this.text = text;
        this.key = key;
    }

    public String getText() {
        return text;
    }

    public String getValue() {
        return name();
    }

    public String getKey() {
        return key;
    }

    public static PayloadParserType getByKey(String key) {
        for (PayloadParserType type : values()) {
            if (type.getKey().equals(key)) {
                return type;
            }
        }
        return null;
    }
}
